def max_sub_sum(nums):
    if not nums:
        return 0
    
    max_sum = sum = nums[0]
    
    for num in nums[1:]:
        sum = max(num, sum + num)
        max_sum = max(max_sum, sum)
    
    return max_sum

print(max_sub_sum([1, -2, 3, 5, -1]))  
print(max_sub_sum([1, -2, 3, -8, 5, 1]))  
print(max_sub_sum([1, -2, 3, -2, 5, 1]))  
